package com.cn.example;

import com.cn.common.ServerThread;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

public class Test {

    private List<TestServer2> list = new ArrayList<>();

    public Test() {
    }


    public void demo1() {
        System.out.println("线程：" + Thread.currentThread().getId());
    }

    class TestServer2 extends ServerThread {

        private Test test;


        public TestServer2(final Test test) {
            this.test = test;
            start();
        }

        @Override
        public String getServiceName() {
            return TestServer2.class.getName();
        }

        @Override
        public void run() {
            while (!isStopped()) {
                waitForRunning(2000);
                test.demo1();
            }
        }
    }

    public void t(Test test) {
        ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(5);
        for (int i = 0; i < 2; i++) {
            scheduledExecutorService.scheduleAtFixedRate(new Runnable() {
                @Override
                public void run() {
                    TestServer2 t = new TestServer2(test);
                    test.list.add(t);
                }
            }, 1, 10, TimeUnit.SECONDS);
        }
    }

    public static void main(String[] args) {
        boolean flag = false;
        boolean f1 = true;
        flag = flag && f1;
        System.out.println(f1);
    }

}
